<?php
class Training_DateController extends Zendvn_Controller_Action{
    
    public function init() {
        parent::init();
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
    }
    
    public function indexAction() {
        //Khoi tao
//        date_default_timezone_set('Asia/Tokyo');
        $date = new Zend_Date();
        $date->setTimezone('America/Los_Angeles');
        echo '<pre>';
        print_r($date);
        echo '<pre>';
    }
    
    public function index2Action() {
        echo '<br>' . time();
        $date = new Zend_Date();
        echo '<br>' . $date->get();
    }
    
    public function index3Action() {

        $date = new Zend_Date();
        
        $date->setTimezone('Asia/Ho_Chi_Minh');
        echo '<br>' . $date->get(Zend_Date::DATETIME_FULL, 'vi_VN');
        
        $date->setTimezone('America/Los_Angeles');
        echo '<br>' . $date->get(Zend_Date::DATETIME_FULL, 'vi_VN');
        
        $date->setTimezone('Asia/Tokyo');
        echo '<br>' . $date->get(Zend_Date::DATETIME_FULL, 'vi_VN');
    }
    
    public function index4Action() {

        $date = new Zend_Date();
        
        $date->setTimezone('Asia/Ho_Chi_Minh');
        echo '<br>' . $date->get(Zend_Date::DATETIME_FULL, 'en_US');
        
        $date->setTimezone('America/Los_Angeles');
        echo '<br>' . $date->get(Zend_Date::DATETIME_FULL, 'en_US');
        
        $date->setTimezone('Asia/Tokyo');
        echo '<br>' . $date->get(Zend_Date::DATETIME_FULL, 'en_US');
    }
    
    public function index5Action() {
        $date = new Zend_Date();
        echo '<br>' . $date->get(Zend_Date::DATES, 'en_US');
        echo '<br>' . $date->getDate('en_US')->toString(Zend_Date::DATE_MEDIUM, 'iso');
        echo '<br>' . $date->getDate()->toString(Zend_Date::DATES, 'iso', 'en_US');
    }
    
    public function index6Action() {
        $date = new Zend_Date();
        echo '<br>' . $date->get(Zend_Date::DATE_FULL, 'en_US');
        echo '<br>' . $date->getDate('en_US')->toString(Zend_Date::DATE_FULL, 'iso');
        echo '<br>' . $date->getDate()->toString(Zend_Date::DATE_FULL, 'iso', 'en_US');
    }
    
    public function index7Action() {
        $date = new Zend_Date();
        echo '<br>' . $date->get(Zend_Date::HOUR, 'en_US');
        echo '<br>' . $date->getHour('en_US')->toString(Zend_Date::HOUR, 'iso');
        echo '<br>' . $date->getHour()->toString(Zend_Date::HOUR, 'iso', 'en_US');
    }
    
    public function index8Action() {
        $date = new Zend_Date();
        echo '<br>' . $date->get(Zend_Date::DATETIME_FULL, 'vi_VN');
        echo '<br>' . $date->getDay('vi_VN')->toString(Zend_Date::DAY, $type);
        echo '<br>' . $date->getMonth('vi_VN')->toString(Zend_Date::MONTH, $type);
        echo '<br>' . $date->getYear('vi_VN')->toString(Zend_Date::YEAR, $type);
    }
    
    public function index9Action() {
        $date = '15.03.2000';
        
        if(Zend_Date::isDate($date)){
            echo '<br> OK';
        }else{
            echo '<br> NOT OK';
        }
    }
    
    public function index9aAction() {
        $date = '01 February 2000';
        
        if(Zend_Date::isDate($date, 'dd MM yyyy')){
            echo '<br> OK';
        }else{
            echo '<br> NOT OK';
        }
    }
    
    public function index10Action() {
        $date = new Zend_Date();
        $date->set('20-10-2010 15:20:30', $part, 'vi_VN');
        echo '<br> Hom nay la: ' . $date->get(Zend_Date::DATETIME_MEDIUM, 'vi_VN');
        echo '<br> Thoi gian cua banner quang cao la 7 ngay';
        $date->addDay(7, Zend_Date::DAY);
        echo '<br> Ngay ket thuc la: ' . $date->get(Zend_Date::DATETIME_MEDIUM, 'vi_VN');
    }
    
    public function index11Action() {
        $date = new Zend_Date();
        echo '<br> Hom nay la: ' . $date->get(Zend_Date::WEEKDAY, 'vi_VN');
        echo '<br> Thoi gian cua banner quang cao la 7 ngay';
        $date->subDay(7, Zend_Date::DAY);
        echo '<br> Ngay ket thuc la: ' . $date->get(Zend_Date::WEEKDAY, 'vi_VN');
    }
    
    public function index12Action() {
        $date = new Zend_Date();
        $date->set('11-06-2015 15:20:30', $part, 'vi_VN');
        echo $date->compare(2, Zend_Date::HOUR, 'vi_VN');
        //0: đúng giờ
        //-1: trễ giờ
        //1: quá giờ
    }
    
    public function index13Action() {
        $date = new Zend_Date();
        $date->set('11-06-2015 15:20:30', $part, 'vi_VN');
        if($date->equals(16, Zend_Date::HOUR, 'vi_VN')){
            echo 'Equals';
        }else{
            echo 'Not Equals';
        }
        
        $date->set('20-10-2015 13:30:30', null, 'vi_VN');
        echo $date->get(Zend_Date::TIME_SHORT);
        
        $now = '13:20';
        if($date->isEarlier($now, Zend_Date::TIME_SHORT, 'vi_VN') == 0){
            echo '<br> Sớm hơn';
        }
        
        $now = '13:40';
        if($date->isLater($now, Zend_Date::TIME_SHORT, 'vi_VN') == 0){
            echo '<br> Muộn hơn';
        }
    }
}